package com.classes.constants;

import com.classes.constants.logic.Constants;
import com.classes.constants.logic.Constants_class_info;
import com.classes.constants.logic.Constants_double_info;
import com.classes.constants.logic.Constants_field_ref_info;
import com.classes.constants.logic.Constants_float_info;
import com.classes.constants.logic.Constants_integer_info;
import com.classes.constants.logic.Constants_interface_method_ref_info;
import com.classes.constants.logic.Constants_invoke_dynamic_info;
import com.classes.constants.logic.Constants_long_info;
import com.classes.constants.logic.Constants_method_handle_info;
import com.classes.constants.logic.Constants_method_ref_info;
import com.classes.constants.logic.Constants_method_type_info;
import com.classes.constants.logic.Constants_name_and_type_info;
import com.classes.constants.logic.Constants_string_info;
import com.classes.constants.logic.Constants_utf_info;

public class ConstantsUtils {

    /**
     * 根据类型获得常量实例
     *
     * @param tag
     * @return
     */
    public static Constants getConstantsInstance(int tag) {
        ConstantsTypeEnum byType = ConstantsTypeEnum.getByType(tag);
        Constants constant = null;
        switch (byType) {
            case UTF_8_INFO: {
                constant = new Constants_utf_info((byte) tag);
                break;
            }
            case INTEGER_INFO: {
                constant = new Constants_integer_info((byte) tag);
                break;
            }
            case FLOAT_INFO: {
                constant = new Constants_float_info((byte) tag);
                break;
            }
            case LONG_INFO: {
                constant = new Constants_long_info((byte) tag);
                break;
            }
            case DOUBLE_INFO: {
                constant = new Constants_double_info((byte) tag);
                break;
            }
            case CLASS_INFO: {
                constant = new Constants_class_info((byte) tag);
                break;
            }
            case STRING_INFO: {
                constant = new Constants_string_info((byte) tag);
                break;
            }
            case FIELD_REF_INFO: {
                constant = new Constants_field_ref_info((byte) tag);
                break;
            }
            case METHOD_REF_INFO: {
                constant = new Constants_method_ref_info((byte) tag);
                break;
            }
            case INTERFACE_METHOD_REF_INFO: {
                constant = new Constants_interface_method_ref_info((byte) tag);
                break;
            }
            case NAME_AND_TYPE_INFO: {
                constant = new Constants_name_and_type_info((byte) tag);
                break;
            }
            case METHOD_HANDLE_INFO: {
                constant = new Constants_method_handle_info((byte) tag);
                break;
            }
            case METHOD_TYPE_INFO: {
                constant = new Constants_method_type_info((byte) tag);
                break;
            }
            case INVOKE_DYNAMIC_INFO: {
                constant = new Constants_invoke_dynamic_info((byte) tag);
                break;
            }

        }
        return constant;
    }
}
